tools: libxc: allow HVM firmware to be loaded at an arbitrary alignment
authorIan Campbell <ian.campbell@citrix.com>
Tue, 24 May 2011 17:24:05 +0000 (18:24 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 24 May 2011 17:24:05 +0000 (18:24 +0100)
Enables direct loading of e.g. seabios.elf.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xc_hvm_build.c

index 9fe91fd86cdbee0a993d191f492f483328861a4f..c32be4e91c0e6db82e635744f53b25b204d4e02b 100644 (file)
@@ -88,7 +88,9 @@ static int loadelfimage(
     struct elf_binary *elf, uint32_t dom, unsigned long *parray)
 {
     privcmd_mmap_entry_t *entries = NULL;
-    size_t pages = (elf->pend - elf->pstart + PAGE_SIZE - 1) >> PAGE_SHIFT;
+    unsigned long pfn_start = elf->pstart >> PAGE_SHIFT;
+    unsigned long pfn_end = (elf->pend + PAGE_SIZE - 1) >> PAGE_SHIFT;
+    size_t pages = pfn_end - pfn_start;
     int i, rc = -1;
 
     /* Map address space for initial elf image. */
@@ -105,6 +107,8 @@ static int loadelfimage(
     if ( elf->dest == NULL )
         goto err;
 
+    elf->dest += elf->pstart & (PAGE_SIZE - 1);
+
     /* Load the initial elf image. */
     elf_load_binary(elf);
     rc = 0;
@@ -172,12 +176,6 @@ static int setup_guest(xc_interface *xch,
         goto error_out;
     }
 
-    if ( (elf.pstart & (PAGE_SIZE - 1)) != 0 )
-    {
-        PERROR("Guest OS must load to a page boundary.");
-        goto error_out;
-    }
-
     IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"
             "  Loader:        %016"PRIx64"->%016"PRIx64"\n"
             "  TOTAL:         %016"PRIx64"->%016"PRIx64"\n"